# -*- encoding: utf-8 -*-
# @File    :   config.py
# @Time    :   2021/07/29 10:16:12
# @Author  :   wudongmin
# @Contact :   wudongmin@xroom.net
# @version   :  1.0

import os
import yaml


class ConfigYaml(object):

    def __init__(self) -> None:
        super().__init__()

    def get_config_file(self):
        config_path = os.path.abspath(os.path.dirname(__name__))
        config_name = "config.yaml"
        return os.path.join(config_path, config_name)

    def get_all_config(self):
        f = open(self.get_config_file())
        content = f.read()
        return yaml.load(content, Loader=yaml.FullLoader) 

    def get_database_config(self):
        p = self.get_all_config()["postgres"]
        db_url = "postgresql+psycopg2://{}:{}@{}:{}/{}".format(p["user"], p["password"], p["host"], p["port"], p["database"])
        return db_url


config = ConfigYaml()
